package com.basic.java.spring5.AOP.cglibactiveproxy.proxy;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * 增强类
 * 创建时间：2022/3/14 13:37
 *
 * @author gejin
 */
@Component
@Aspect // 生成代理对象
public class UserProxy {
    // 相同切入点提取
    @Pointcut(value = "execution(* com.basic.java.spring5.AOP.cglibactiveproxy.entity.user.add(..))")
    public void pointCutDemo() {
    }

    // 前置通知
    @Before(value = "pointCutDemo()")
    public void before() {
        System.out.println("before ....");
    }


    // 后置通知
    @AfterReturning(value = "pointCutDemo())")
    public void afterReturning() {
        System.out.println("afterReturning ....");
    }

    // 最终通知
    @After(value = "pointCutDemo())")
    public void after() {
        System.out.println("after...");
    }

    // 异常通知
    @AfterThrowing(value = "pointCutDemo())")
    public void afterThrowing() {
        System.out.println("afterThrowing...");
    }

    // 环绕通知
    @Around(value = "pointCutDemo())")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕通知之前...");
        // 被增强的方法
        proceedingJoinPoint.proceed();
        System.out.println("环绕通知之后...");
    }
}
